//
//  LoginHttpTools.m
//  Village
//
//  Created by 程虎 on 2017/9/25.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "LoginHttpTools.h"

@implementation LoginHttpTools

#pragma mark - 账号、手机号登录
+ (void)LoginWithName:(NSString *)nameStr WithPW:(NSString *)pwStr WithTypes:(NSInteger )types Success:(void (^)(NSDictionary *valueDict))success failure:(void (^)(NSString *error))failure
{
    NSMutableDictionary *bean = [NSMutableDictionary dictionary];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [bean setValue:dict forKey:@"entitybean"];
    [dict setObject:nameStr forKey:types == 0 ? @"account" : @"phone"];
    [dict setObject:pwStr forKey:types == 0 ? @"passwordcode" : @"msgcode"];
    [NetRequestClass Post:types == 0 ? AccountLoginURL : PhoneLoginURL Parameters:bean success:^(id result) {
        if (success) {
            success(result);
        }
    } failure:^(id valueCode, id error) {
        if (failure) {
            failure(error);
        }
    }];
}

#pragma mark - 第三方登录
+ (void)LoginWithThirdPartyWithQQID:(NSString *)QQID WithWXID:(NSString *)WXID Success:(void (^)(NSDictionary *valueDict))success failure:(void (^)(NSString *error))failure
{
    NSMutableDictionary *entitybean = [NSMutableDictionary dictionary];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [entitybean setValue:dict forKey:@"entitybean"];
    [dict setObject:QQID forKey:@"qqopenid"];
    [dict setObject:WXID forKey:@"wechatopenid"];
    [NetRequestClass Post:ThirdPartyLoginURL Parameters:entitybean success:^(id result) {
        if (success) {
            success(result);
        }
    } failure:^(id valueCode, id error) {
        if (failure) {
            failure(error);
        }
    }];
}

#pragma mark - 第三方绑定微信、QQ
+ (void)AccountBindWithQQID:(NSString *)QQID WithWXID:(NSString *)WXID Success:(void (^)(NSDictionary *valueDict))success failure:(void (^)(NSString *error))failure
{
    NSMutableDictionary *entitybean = [NSMutableDictionary dictionary];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [entitybean setValue:dict forKey:@"entitybean"];
    [dict setObject:[Globle getInstance].account.userid.length > 0 ? [Globle getInstance].account.userid : @"" forKey:@"id"];
    [dict setObject:QQID forKey:@"qqopenid"];
    [dict setObject:WXID forKey:@"wechatopenid"];
    [NetRequestClass Post:AccountBindURL Parameters:entitybean success:^(id result) {
        if (success) {
            success(result);
        }
    } failure:^(id valueCode, id error) {
        if (failure) {
            failure(error);
        }
    }];
}
@end
